<template>
  <div ref="container">
    <breadcrumb :breadList="breadList" :name="name">
      <div class="handle-box" slot="handleContent">
        <div class="handle-btn">
          <a-button class="common-btn" @click="addSupplier">添加供应商</a-button>
        </div>
        <div class="handle-btn">
          <a-button class="common-btn" @click="exportList">导出列表</a-button>
        </div>
      </div>
    </breadcrumb>
    <a-card>
      <a-form @submit="handleSubmit" :form="form">
        <a-row clss="form-row" :gutter="16">
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="企业名称">
              <a-textarea v-model="queryParam.name" rows="1" placeholder="企业名称"/>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="企业类型">
              <a-select v-model="queryParam.type">
                <a-select-option value="1">设备厂商</a-select-option>
                <a-select-option value="2">施工企业</a-select-option>
                <a-select-option value="3">监理企业</a-select-option>
                <a-select-option value="4">设计企业</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="商品名称">
              <a-textarea v-model="queryParam.details" rows="1" placeholder="商品名称"/>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="" :colon="false">
              <a-button class="common-btn" style="margin-top:42px;" @click="toSearch('2')">查询</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card>
      <a-table :columns="columns" :dataSource="loadData" bordered :loading="loading" :pagination="false">
        <template slot="operation" slot-scope="text, record">
          <p style="display:inline" @click="go_toOperation('detail',record)">
            <a href="javascript:;">详情</a>
            <a-divider type="vertical"/>
          </p>
          <p style="display:inline" @click="go_toOperation('modify',record)">
            <a href="javascript:;">编辑</a>
          </p>
        </template>
        <template slot="details" slot-scope="text, record">
          <p @click="$refs.detailsModel.add(record)" style="margin-bottom:0px;">
            <a href="javascript:;" style="text-decoration:underline;">查看明细</a>
          </p>
        </template>
      </a-table>
      <details-model ref="detailsModel"></details-model>
    </a-card>
  </div>
</template>

<script>
import Breadcrumb from '@/components/tools/Breadcrumb'
import detailsModel from './detailsModel'
export default {
  name: 'SupplierManagementList',
  components: {
    Breadcrumb,
    detailsModel
  },
  data () {
    return {
      name: '',
      breadList: [],
      loading: false,
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '企业全称',
          dataIndex: 'name'
        }, {
          title: '联系人',
          dataIndex: 'person'
        }, {
          title: '联系电话',
          dataIndex: 'phone'
        }, {
          title: '企业类型',
          dataIndex: 'type'
        }, {
          title: '设备明细',
          dataIndex: 'details',
          scopedSlots: { customRender: 'details' }
        }, {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: []
    }
  },
  created () {
    this.loading = true
    this.getBreadCrumb()
    setTimeout(() => {
      this.getData('1')
    }, 1000)
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
    },
    getData (code) {
      const data = [
        {
          key: '1',
          name: '世界名牌',
          person: '王老五',
          phone: '18888888888',
          type: '设备厂商',
          details: '专业服务一条龙'
        }, {
          key: '2',
          name: '世界名牌',
          person: '王老五',
          phone: '18888888888',
          type: '设备厂商',
          details: '专业服务一条龙'
        }, {
          key: '3',
          name: '世界名牌',
          person: '王老五',
          phone: '18888888888',
          type: '设备厂商',
          details: '专业服务一条龙'
        }, {
          key: '4',
          name: '世界名牌',
          person: '王老五',
          phone: '18888888888',
          type: '设备厂商',
          details: '专业服务一条龙'
        }, {
          key: '5',
          name: '世界名牌',
          person: '王老五',
          phone: '18888888888',
          type: '设备厂商',
          details: '专业服务一条龙'
        }, {
          key: '6',
          name: '世界名牌',
          person: '王老五',
          phone: '18888888888',
          type: '设备厂商',
          details: '专业服务一条龙'
        }
      ]
      if (code === '1') {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
        }, 1000)
      } else {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
          this.$success({
            title: '查询成功'
          })
        }, 1000)
      }
    },
    toSearch (status) {
      this.loading = true
      this.getData(status)
    },
    handleSubmit () {
      console.log('ttt')
    },
    addSupplier () {
      this.$router.push({
        name: 'addSupplier'
      })
    },
    exportList () {
      this.$success({
        title: '导出成功'
      })
    },
    go_toOperation (type, record) {
      this.$router.push({
        name: 'addSupplier',
        query: {
          type: type,
          proDetails: JSON.stringify(record)
        }
      })
    }
  }
}

</script>

<style lang="less" scoped>
// .handle-box {
//   display: flex;
//   margin-bottom: 10px;
//   margin-left: 800px;
// }
// .handle-btn {
//   margin-left:5px;
// }
</style>
